package com.google.code.server4j.thread;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.google.code.server4j.component.BaseLifeCycle;

public class Server4jTheadPool extends BaseLifeCycle implements ThreadPool {

	private int minSpareThreads;
	private int maxThread;
	private int maxIdleTime;
	
	@Override
	public void doInit() throws Exception {
		System.out.println("init 线程池");
	}

	@Override
	public void doStart() throws Exception {
		System.out.println("start 线程池");
		ThreadPoolExecutor pool = new ThreadPoolExecutor(minSpareThreads, maxThread, maxIdleTime,
				TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
		pool.execute(new Runnable() {
			@Override
			public void run() {
				while(true){}
			}
		});
	}

	@Override
	public void doStop() throws Exception {
		System.out.println("stop 线程池");
	}

	public int getMinSpareThreads() {
		return minSpareThreads;
	}

	public void setMinSpareThreads(int minSpareThreads) {
		this.minSpareThreads = minSpareThreads;
	}

	public int getMaxThread() {
		return maxThread;
	}

	public void setMaxThread(int maxThread) {
		this.maxThread = maxThread;
	}

	public int getMaxIdleTime() {
		return maxIdleTime;
	}

	public void setMaxIdleTime(int maxIdleTime) {
		this.maxIdleTime = maxIdleTime;
	}
	
}
